package com.community.zhihuishequ.utils;

import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * RXView便利方法
 */
public class ViewUtil {
    public static Observable<Object> clickWithDebounce(View view) {
        return RxView.clicks(view).debounce(250, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<Object> clickWithDebounce(View view, long timeout) {
        return RxView.clicks(view).debounce(timeout, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread());
    }

    /**
     * 给textView设置Drawable
     *
     * @param textView View
     */
    public static void setTextDrawable(TextView textView, Drawable left, Drawable top, Drawable right, Drawable bottom) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            textView.setCompoundDrawablesRelativeWithIntrinsicBounds(left, top, right, bottom);
        } else textView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
    }

    /**
     * 给textView设置Drawable
     * @param textView View
     */
    public static void setTextDrawable(TextView textView, int left, int top, int right, int bottom) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            textView.setCompoundDrawablesRelativeWithIntrinsicBounds(left, top, right, bottom);
        } else textView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
    }
}
